﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class User_passwordchange : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.labID.Text = Session["tid"].ToString();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        PM.PMSys.account aaccount = new PM.PMSys.account();
        string UserId = this.labID.Text.Trim();
        string UserPwd = this.txtOldPwd.Text.Trim();
        string NewPwd1 = this.txtNewPwd1.Text.Trim();
        string NewPwd2 = this.txtNewPwd2.Text.Trim();
        int s = aaccount.CheckPwd(UserId, UserPwd);
        this.Label1.Text = s.ToString();
        if (NewPwd1.Equals(NewPwd2))
        {
            string salt = PM.Code.Web.safety.get_GenerateSalt();//重新生成密码加密权值
            string pwd = PM.Code.Web.safety.EncodePassword(NewPwd1, salt);//设置新密码
            int result = aaccount.ResetPwd(UserId, pwd, salt);
            if (result > 0)
            {
                this.note.InnerHtml = "<span style='color:Green'>您的新密码设置成功！</span>";
            }
            else
                this.note.InnerHtml = "<span style='color:Red'>由于您的帐号被删除，新密码设置失败！</span>";
        }
        else
        {
            this.note.InnerHtml = "<span style='color:Red'>两次密码输入不同，请重新输入！</span>";
            this.txtNewPwd1.Text = "";
            this.txtNewPwd2.Text = "";
            return;
        }
        this.txtOldPwd.Text = "";
        this.txtNewPwd1.Text = "";
        this.txtNewPwd2.Text = "";
    }
}
